import Vuex from 'vuex'
import Vue from 'vue'
export default function initPrompt(v) {
	v.use(Vuex)
	// 挂在store到全局Vue原型上
	v.prototype.$promptStore = new Vuex.Store({
		state: {
			show: false,
			title: 'title',
			message: "success",
			buttonName: 'buttonName',
			bgImage: 'bgImage',
			confirm: null
		},
		mutations: {
			// 隐藏
			hidePrompt(state) {
				state.show = false
			},
			// 显示
			showPrompt(state, data) {
				state.message = data.message
				state.title = data.title
				state.confirm = data.confirm
				state.buttonName = data.buttonName
				state.bgImage = data.bgImage
				state.show = true
			},
			// 确认
			confirm(state, data) {
				return state.confirm(data)
			}
		}
	})
	// 注册$showPrompt到Vue原型上，以方便全局调用
	Vue.prototype.$showPrompt = function (option) {
		if (typeof option === 'object') {
			v.prototype.$promptStore.commit('showPrompt', option)
		} else {
			throw "配置项必须为对象传入的值为：" + typeof option;
		}
	}
}